class CustomMapping extends JiraMapping
{

    mapping()
    {
        return {
            key: "customfield_10700", // Ticket Id
            fields: {
                // source field : target field
                project:"project",
                issuetype:"issuetype",
                status:"status", // Can not direct set status
                summary:"summary",
                description:"description",
                assignee:"assignee", // need convert to right email
                priority:"priority", // priority.name
                timetracking:"timetracking",
                fixVersions:"fixVersions", // array
                customfield_13431:"customfield_10802", // Ticket Action Object.value
                customfield_15300:"customfield_10803", // Area Impact Object.value
                customfield_14800:"customfield_10800", // Region Array value
                customfield_13423:"customfield_10801", // Country Covered Array value
                customfield_13700:"developer" // developer Array value, hard code index 0
            }
        };
    }

    assignee(origData)
    {
        // different name
        let name = origData.match(/(.*)@.*/);
        if (name.length>=2) {
            origData = name[1];
        }

        switch(origData) {
            case "ting.lou":
                origData = 'luo.luo';
            break;
            case "brad.chen2":
                origData = 'brad.chen';
            default:
            break;
        }

        origData = origData + '@shinetechmagento.com';
        return origData;
    }

    priority(origData)
    {
        let map = {
            "Urgent":"Highest",
            "1 - Urgent":"Highest",
            "2 - High":"Highest",
            "Showstopper":"Highest",
            "3 - Medium":"Medium"
        }

        try {
            let _configData = localStorage.getItem('config');
            if (_configData.length>0) {
                _configData = JSON.parse(_configData);
                if (_configData.lavelMapping) {
                    map = JSON.parse(_configData.lavelMapping); // update mapping
                }
            }
        } catch (e) {
            console.error('priority mapping error', e);
        }

        if (map[origData]) {
            return map[origData];
        }
        return origData;
    }

    customfield_13700(origData)
    {
        let name = origData.match(/(.*)@.*/);
        if (name.length>=2) {
            origData = name[1];
        }

        switch(origData) {
            case "ting.lou":
                origData = 'luo.luo';
            break;
            default:
            break;
        }

        // need use localStrong data replace
        // or through jQuery get developer from page
        origData = jQuery('#developer').val();
        if (!origData) {
            origData = jQuery('.jsonform-error-fields---developer input').val();
        }

        origData = origData + '@shinetechmagento.com';
        return origData;
    }

    afterConvert(fields)
    {
        if (fields.customfield_10802) {
            if (fields.customfield_10802.value=="Code change") {
                fields.issuetype.name = "Bug";
            } else {
                fields.issuetype.name = "Task";
            }
        } else {
             let type = jQuery('#task-type').val();
             if (!type) {
                type = jQuery('.jsonform-error-fields---customfield_13431---value select').val();
             }
             switch (type) {
                case "Code change":
                    fields.issuetype.name = "Bug";
                break;
                default:
                    fields.issuetype.name = "Task";
                break;
             }
             fields.customfield_10802 = {value:type};
        }

        delete fields.project.name;
        fields.project.key = 'HSI';

        return fields;
    }
}